package com.stlm2.util;

/**
 * 作者: fcy
 * 时间: 2017/5/25
 * 描述：百度地图工具类
 */
public class MapUtil {
    /**
     * 作者: fcy
     * 时间: 2017/5/25
     * 描述：根据商家地址获取坐标
     */
    public static String getPoint(String city){
        String point=null;
        try {
            //702632E1add3d4953d0f105f27c294b9
            java.io.InputStream l_urlStream;
            java.net.URL l_url = new java.net.URL("http://api.map.baidu.com/geocoder/v2/?address="+city.replaceAll(" ", "")+"&output=json&ak=CCT7e4P08ATzV720HxP1wrw0mImGMUc5&callback=showLocation");
            java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
            l_connection.connect();
            l_urlStream = l_connection.getInputStream();
            java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));
            String str=l_reader.readLine();
            //用经度分割返回的网页代码
            String s=","+"\""+"lat"+"\""+":";
            String strs[]=str.split(s, 2);
            String s1="\""+"lng"+"\""+":";
            String a[]=strs[0].split(s1, 2);
            //System.out.println("x:"+a[1]);
            //shop.setLng(a[1]);
            s1="}"+","+"\"";
            String a1[]=strs[1].split(s1, 2);
            //System.out.println("y:"+a1[0]);
            point=a1[0]+","+a[1];
            //shop.setLat(a1[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return point;
    }
}
